<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ include file="/commons/global.jsp" %>
<script type="text/javascript">
    var associationDataGrid;
    var associationDepartmentTree;

    $(function() {
        associationDepartmentTree = $('#associationDepartmentTree').tree({
        	lines:true,
            url : '${path }/admin/association/tree',
            parentField : 'pid',
            lines : true,
            animate: true,
            onClick : function(node) {
            	$(this).tree('toggle', node.target);
            	$('#departmentId').val(node.id);
            	$(".association").layout('panel','center').panel('setTitle','当前栏目：'+node.text+" 》 信息列表");
                associationDataGrid.datagrid('load', {
                    departmentid: node.id
                });
            }
        });

        associationDataGrid = $('#associationDataGrid').datagrid({
            url : '${path }/admin/association/dataGrid',
            fit : true,
            striped : true,
            rownumbers : true,
            pagination : true,
            singleSelect : true,
            idField : 'id',
            sortName : 'sequence',
	        sortOrder : 'asc',
            pageSize : 10,
            pageList : [ 10, 20, 30, 40, 50 ],
            columns : [ [ {
                width : '150',
                title : '社团名称',
                field : 'association_name',
                sortable : true
            }, {
                width : '80',
                title : '创立日期',
                field : 'createdate',
                sortable : true
            },{
                width : '150',
                title : '邮箱',
                field : 'email',
                sortable : true
            },{
                width : '80',
                title : '第一负责人',
                field : 'first_person',
                sortable : true
            },{
                width : '120',
                title : '负责人电话',
                field : 'first_phone',
                sortable : true
            },{
                width : '80',
                title : '指导老师',
                field : 'tutor',
                sortable : true
            },{
                width : '120',
                title : '指导老师电话',
                field : 'tutor_phone',
                sortable : true
            },{
                width : '50',
                title : '排序',
                field : 'sequence'
            },{
                width : '60',
                title : '状态',
                field : 'status',
                sortable : true,
                formatter : function(value, row, index) {
                    switch (value) {
                    case 0:
                        return '停用';
                    case 1:
                        return '正常';
                    }
                }
            }
            /* , {
                field : 'action',
                title : '操作',
                width : 130,
                formatter : function(value, row, index) {
                    var str = '';
                        <shiro:hasPermission name="/admin/association/edit">
                            str += $.formatString('<a href="javascript:void(0)" class="association-easyui-linkbutton-edit" data-options="plain:true,iconCls:\'fi-pencil icon-blue\'" onclick="editAssociationFun(\'{0}\');" >编辑</a>', row.id);
                        </shiro:hasPermission>
                        <shiro:hasPermission name="/admin/association/delete">
                            str += '&nbsp;&nbsp;|&nbsp;&nbsp;';
                            str += $.formatString('<a href="javascript:void(0)" class="association-easyui-linkbutton-del" data-options="plain:true,iconCls:\'fi-x icon-red\'" onclick="deleteAssociationFun(\'{0}\');" >删除</a>', row.id);
                        </shiro:hasPermission>
                    return str;
                }
            } */
            ] ],
            onLoadSuccess:function(data){
                $('.association-easyui-linkbutton-edit').linkbutton({text:'编辑'});
                $('.association-easyui-linkbutton-del').linkbutton({text:'删除'});
            },
            toolbar : '#associationToolbar'
        });
    });
      //获取父id
    function getParentId(){
    	var parentId=$("#parentid").val();
    	return parentId;
    }  
    function addAssociationFun() {
    	parent.addFrameTab('社团编辑','${path }/admin/association/add','');
    }
    
    function deleteAssociationFun(id) {
     if (id == undefined) {
        	var rows = associationDataGrid.datagrid('getSelections');
        	id = rows[0].id;
        } else {
            associationDataGrid.datagrid('unselectAll').datagrid('uncheckAll');
        }
        parent.$.messager.confirm('询问', '您是否要删除当前信息？', function(b) {
            if (b) {
                progressLoad();
                $.post('${path }/admin/association/delete', {
                    id : id
                }, function(result) {
                    if (result.success) {
                        parent.$.messager.alert('提示', result.msg, 'info');
                        associationDataGrid.datagrid('reload');
                        $("#associationDepartmentTree").tree("reload");
                    } else {
                        parent.$.messager.alert('错误', result.msg, 'error');
                    }
                    progressClose();
                }, 'JSON');
            }
        });
    }
    
    function editAssociationFun(id) {
        if (id == undefined) {
            var rows = associationDataGrid.datagrid('getSelections');
            id = rows[0].id;
        } else {
            associationDataGrid.datagrid('unselectAll').datagrid('uncheckAll');
        }
        parent.addFrameTab('社团编辑','${path }/admin/association/edit?id='+id,'');
    }
    
    function searchAssociationFun() {
    	$("#associationDepartmentTree").tree("reload");
        associationDataGrid.datagrid('load', $.serializeObject($('#searchAssociationForm')));
    }
    function cleanAssociationFun() {
        $('#searchAssociationForm input').val('');
        associationDataGrid.datagrid('load', {});
    }
</script>
<div class="easyui-layout association" data-options="fit:true,border:false">
 <div data-options="region:'north',border:false" style="height: 30px; overflow: hidden;background-color: #fff">
        <form id="searchAssociationForm">
       		<input name="departmentId" type="hidden" id="departmentId" value=""/>
            <table>
                <tr>
                    <th>社团名称:</th>
                    <td><input name="associationName" placeholder="请输入社团标题"/>
                     	<a href="javascript:void(0);" class="easyui-linkbutton" data-options="iconCls:'fi-magnifying-glass',plain:true" onclick="searchAssociationFun();">查询</a>
                	</td>
                </tr>
            </table>
        </form>
    </div>
    <div data-options="region:'center',border:true,title:'信息列表'" >
        <table id="associationDataGrid" data-options="fit:true,border:false"></table>
    </div>
    <div data-options="region:'west',border:true,split:false,hide:true,title:'社团栏目'" refresh="reloadAll" expand="expandAll" collapse="collapseAll" style="width:150px; ">
        <ul id="associationDepartmentTree" fit="true" style="width:160px;margin: 10px 10px 10px 10px"></ul>
    </div>
</div>
<div id="associationToolbar" style="display: none;">
   <%--  <shiro:hasPermission name="/admin/association/add">
        <a onclick="addAssociationFun();" href="javascript:void(0);" class="easyui-linkbutton" data-options="plain:true,iconCls:'fi-plus icon-green'">添加</a>
    </shiro:hasPermission> --%>
</div>